import Vue from 'vue'
import App from './App.vue'

//关闭生产提示
Vue.config.productionTip = false

//UI
import ElementUI from 'element-ui'
Vue.use(ElementUI)

import 'element-ui/lib/theme-chalk/index.css'
import 'element-ui/lib/index.js'





//路由
import router from './router'

//vuex状态管理
import store from './store'

import request from './request'
Vue.prototype.$http = request;



//进度条插件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({
    easing: 'ease', // 动画方式
    speed: 600, // 递增进度条的速度
    showSpinner: true, // 是否显示加载ico
    trickleSpeed: 200, // 自动递增间隔
    minimum: 0.3 // 初始化时的最小百分比
  });



  //路由钩子
router.beforeEach((to, from , next) => {
  NProgress.start();
  
  //判断是否需要登录认证
  var isAuthor =to.matched.some((record) => {
      return record.meta.isAuthor
  })
  if(isAuthor){
    if(localStorage.token){
      next();
    }
    else{
      next({
        path:'/Login'
      });
    }
  }else{
    next();
  }
});
router.afterEach(() => { // 在即将进入新的页面组件前，关闭掉进度条
  NProgress.done()
})


//封装提示
Vue.prototype.showNotify=(msg,type='warning',title='系统提示')=>{
  ElementUI.Notification({
    title: title,
    message: msg,
    type: type
  });
}

//全局时间过滤器
Vue.filter('formatDateTime', function (value) {
  if (value) {
    let date = new Date(value);
    let year = date.getFullYear();
    let month = (date.getMonth() + 1).toString().padStart(2, '0');
    let day = date.getDate().toString().padStart(2, '0');
    let hour = date.getHours().toString().padStart(2, '0');
    let minute = date.getMinutes().toString().padStart(2, '0');
    let second = date.getSeconds().toString().padStart(2, '0');
    
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
